<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<script>
   function vote(pID)
   {
    let isDelay=document.getElementById('cbDelay').checked;
	let delay=isDelay?"?delay=1":"?delay=0";
	 
   fetch("/redis-producer/stock/api2"+delay,{method:"POST"
       ,body:"id="+pID.toString()
       ,headers:{
           'Content-Type': 'application/x-www-form-urlencoded'
       }
   })
	       .then((response)=>{
               response.json().then((json)=>{
                  document.getElementById("span101").innerHTML=json.result.toString()
               })
           })
   }
    
	
    
  </script>

<title>Insert title here</title>
</head>
<body>

<div>
 <div>
   模拟网络卡顿<input type='checkbox' id='cbDelay'/>
   <hr/>
 </div>
  <div>
    <a href='#'>这是id=101的商品</a> <input type='button' value='下单' onclick="vote(101)"/>
      	当前库存:<span id="span101" th:text="${current_stock}"></span>

  </div>

</div>

</body>
</html>